﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="StockCategories.aspx.cs" Inherits="GPSTrackingWebsiteManager.Manager.Pages.StockCategories" %>

<!DOCTYPE html>

<link href="../../Css/GPSTrackingWebsite.css" rel="stylesheet" />
<link href="../../Css/messi.css" rel="stylesheet" />
<script src="../../Javascript/jquery-1.11.1.min.js"></script>
<script src="../../Javascript/messi.js"></script>
<script src="../../Javascript/Custom.js"></script>
<script src="../../Javascript/WindowMessageManager.js"></script>
<link href="../../Css/metro-bootstrap.css" rel="stylesheet" />


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <telerik:RadScriptBlock ID="RadScriptBlock3" runat="server">
        <script type="text/javascript">
            function resizeGrid() {
                var height = window.innerHeight;
                var width = window.innerWidth;

                var tableView = $find("<%=StockCategoriesGrid.ClientID %>");
                tableView.get_element().style.height = height + "px";
                tableView.get_element().style.width = (width / 2) + "px";

                var tableView2 = $find("<%=StockCategoriesGridTree.ClientID %>");
                tableView2.get_element().style.height = height + "px";
                tableView2.get_element().style.width = (width / 2) + "px";


                document.getElementById('HiddenFieldHeight').value = height;
                document.getElementById('HiddenFieldWidth').value = width;
            }

            //Windows Message Manager 
            var objWindowsMessageManager = new WindowsMessageManager();

            var uploadedFilesCount = 0;
            var isEditMode;
            function validateRadUpload(source, e) {
                // When the RadGrid is in Edit mode the user is not obliged to upload file.
                if (isEditMode == null || isEditMode == undefined) {
                    e.IsValid = false;

                    if (uploadedFilesCount > 0) {
                        e.IsValid = true;
                    }
                }
                isEditMode = null;
            }

            function OnClientFileUploaded(sender, eventArgs) {
                uploadedFilesCount++;
            }

            function validationFailed(radAsyncUpload, args) {
                getErrorMessage(radAsyncUpload, args);
            }

            function getErrorMessage(sender, args) {
                var fileExtention = args.get_fileName().substring(args.get_fileName().lastIndexOf('.') + 1, args.get_fileName().length);
                if (args.get_fileName().lastIndexOf('.') != -1) {//this checks if the extension is correct
                    if (sender.get_allowedFileExtensions().indexOf(fileExtention) == -1) {
                        objWindowsMessageManager.show_Error('El tipo de archivo seleccionado no es válido', 'Categorías...');
                    }
                }
                else {
                    objWindowsMessageManager.show_Error('El tipo de archivo seleccionado no es válido', 'Categorías...');
                }
            }

        </script>
    </telerik:RadScriptBlock>
    <style type="text/css">
        .auto-style1 {
            width: 100%;
        }

        .ruBrowse {
            background-position: 0 -46px !important;
            width: 221px !important;
        }
    </style>
</head>
<body onresize="resizeGrid()" style="overflow: hidden">
    <form id="form1" runat="server">
        <telerik:RadWindowManager ID="RadWindowManager1" runat="server"></telerik:RadWindowManager>
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server"></telerik:RadScriptManager>
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" DefaultLoadingPanelID="RadAjaxLoadingPanel1">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="StockCategoriesGrid">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="HiddenFieldHeight" UpdatePanelCssClass="" />
                        <telerik:AjaxUpdatedControl ControlID="HiddenFieldError" UpdatePanelCssClass="" />
                        <telerik:AjaxUpdatedControl ControlID="StockCategoriesGrid" UpdatePanelCssClass="" />
                        <telerik:AjaxUpdatedControl ControlID="StockCategoriesGridTree" UpdatePanelCssClass="" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
                <telerik:AjaxSetting AjaxControlID="StockCategoriesGridTree">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="HiddenFieldHeight" UpdatePanelCssClass="" />
                        <telerik:AjaxUpdatedControl ControlID="HiddenFieldError" UpdatePanelCssClass="" />
                        <telerik:AjaxUpdatedControl ControlID="StockCategoriesGridTree" UpdatePanelCssClass="" />
                        <telerik:AjaxUpdatedControl ControlID="StockCategoriesGrid" UpdatePanelCssClass="" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>
        <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server"></telerik:RadAjaxLoadingPanel>
        <asp:HiddenField ID="HiddenFieldHeight" runat="server" Value="500" />
        <asp:HiddenField ID="HiddenFieldWidth" runat="server" Value="500" />
        <asp:HiddenField ID="HiddenFieldError" runat="server" />
        <asp:HiddenField ID="HiddenFieldTreeViewHasFocus" runat="server" />

        <div>
            <table cellpadding="0" cellspacing="0" class="auto-style1">
                <tr>
                    <td>
                        <telerik:RadGrid ID="StockCategoriesGridTree" runat="server" AutoGenerateColumns="False" CellSpacing="0" GridLines="None" Height="100%" Width="100%" AllowSorting="true" GroupingSettings-CaseSensitive="false" OnNeedDataSource="StockCategoriesGridTree_NeedDataSource" OnItemCommand="StockCategoriesGridTree_ItemCommand" OnDataBound="StockCategoriesGridTree_DataBound">
                            <MasterTableView EditMode="PopUp" EditFormSettings-PopUpSettings-Modal="true" EditFormSettings-CaptionFormatString="Modo Edición" CommandItemDisplay="TopAndBottom" NoMasterRecordsText="No hay registros" AllowFilteringByColumn="true" TableLayout="Auto">
                                <CommandItemTemplate>
                                    <div style="padding: 5px 5px;">
                                        Categorias: 
                                        <asp:LinkButton ID="lbExpandAllNodes" runat="server" CommandName="ExpandAllNodes" Visible='<%# !StockCategoriesGrid.MasterTableView.IsItemInserted %>'><img style="padding-left:10px; padding-right:5px; vertical-align:middle" alt="" src="../../Template/Icons/16px/arrow-expand-icon.png"/>Expandir</asp:LinkButton>
                                        <asp:LinkButton ID="lbCollapseAllNodes" runat="server" CommandName="CollapseAllNodes" Visible='<%# !StockCategoriesGrid.MasterTableView.IsItemInserted %>'><img style="padding-left:10px; padding-right:5px; vertical-align:middle" alt="" src="../../Template/Icons/16px/arrow-expand-icon.png"/>Colapsar</asp:LinkButton>
                                        <asp:LinkButton ID="lbClearSelectionNodes" runat="server" CommandName="ClearSelectionNodes" Visible='<%# !StockCategoriesGrid.MasterTableView.IsItemInserted %>'><img style="padding-left:10px; padding-right:5px; vertical-align:middle" alt="" src="../../Template/Icons/16px/question-type-one-correct-icon.png"/>Categorías Padres</asp:LinkButton>
                                        <asp:LinkButton ID="lbShowError" runat="server" OnClick="lbShowError_Click" Visible='<%# HiddenFieldError.Value == string.Empty ? false : true %>'><img style="padding-left:10px; padding-right:5px; vertical-align:middle" alt="" src="../../Template/Icons/16px/bug-icon.png"/>Error Técnico</asp:LinkButton>
                                    </div>
                                </CommandItemTemplate>

                                <RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column">
                                    <HeaderStyle Width="20px"></HeaderStyle>
                                </RowIndicatorColumn>

                                <ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column">
                                    <HeaderStyle Width="20px"></HeaderStyle>
                                </ExpandCollapseColumn>

                                <Columns>
                                    <telerik:GridTemplateColumn ShowFilterIcon="false">
                                        <ItemTemplate>

                                            <telerik:RadTreeView ID="StockCategoriesGridTreeView" runat="Server" MultipleSelect="false" OnNodeDataBound="StockCategoriesGridTreeView_NodeDataBound" OnNodeClick="StockCategoriesGridTreeView_NodeClick">
                                            </telerik:RadTreeView>
                                        </ItemTemplate>
                                    </telerik:GridTemplateColumn>
                                </Columns>
                            </MasterTableView>
                            <ClientSettings>
                                <Scrolling AllowScroll="True" UseStaticHeaders="True" SaveScrollPosition="True"></Scrolling>
                            </ClientSettings>
                            <FilterMenu EnableImageSprites="False"></FilterMenu>
                        </telerik:RadGrid>


                    </td>
                    <td>

                        <telerik:RadGrid ID="StockCategoriesGrid" runat="server" AllowFilteringByColumn="False" AutoGenerateColumns="False" Height="100%" Width="100%" OnDeleteCommand="StockCategoriesGrid_DeleteCommand" OnInsertCommand="StockCategoriesGrid_InsertCommand" OnNeedDataSource="StockCategoriesGrid_NeedDataSource" OnUpdateCommand="StockCategoriesGrid_UpdateCommand" AllowPaging="True" AllowSorting="true" GroupingSettings-CaseSensitive="false">
                            <MasterTableView EditMode="PopUp" EditFormSettings-PopUpSettings-Modal="true" EditFormSettings-CaptionFormatString="Modo Edición" CommandItemDisplay="TopAndBottom" NoMasterRecordsText="No hay registros" AllowFilteringByColumn="true" TableLayout="Auto">
                                <CommandItemTemplate>
                                    <div style="padding: 5px 5px;">
                                        Categorías: 
                                <asp:LinkButton ID="lbAdd" runat="server" CommandName="InitInsert" Visible='<%# !StockCategoriesGrid.MasterTableView.IsItemInserted %>'><img style="padding-left:10px; padding-right:5px; vertical-align:middle" alt="" src="../../Template/Icons/16px/text-plus-icon.png"/>Nueva Categoría</asp:LinkButton>
                                        <asp:LinkButton ID="lbClearFilters" runat="server" OnClick="lbClearFilters_Click" Visible='<%# !StockCategoriesGrid.MasterTableView.IsItemInserted %>'><img style="padding-left:10px; padding-right:5px; vertical-align:middle" alt="" src="../../Template/Icons/16px/mixx-icon.png"/>Limpiar Filtros</asp:LinkButton>
                                        <asp:LinkButton ID="lbShowError" runat="server" OnClick="lbShowError_Click" Visible='<%# HiddenFieldError.Value == string.Empty ? false : true %>'><img style="padding-left:10px; padding-right:5px; vertical-align:middle" alt="" src="../../Template/Icons/16px/bug-icon.png"/>Error Técnico</asp:LinkButton>
                                    </div>
                                </CommandItemTemplate>

                                <RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column">
                                    <HeaderStyle Width="20px"></HeaderStyle>
                                </RowIndicatorColumn>

                                <ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column">
                                    <HeaderStyle Width="20px"></HeaderStyle>
                                </ExpandCollapseColumn>                              

                                <Columns>
                                    <telerik:GridEditCommandColumn ButtonType="ImageButton" HeaderStyle-Width="25px" EditText="Editar" ItemStyle-Width="20px">
                                        <HeaderStyle Width="25px"></HeaderStyle>

                                        <ItemStyle Width="20px"></ItemStyle>
                                    </telerik:GridEditCommandColumn>
                                    <telerik:GridButtonColumn HeaderStyle-Width="25px" ConfirmText="¿Desea eliminar el registro?" ConfirmDialogType="RadWindow" ConfirmDialogHeight="120" ConfirmDialogWidth="270" ConfirmTitle="Eliminar" ButtonType="ImageButton" CommandName="Delete" Text="Eliminar" ItemStyle-Width="20px">
                                        <HeaderStyle Width="25px"></HeaderStyle>

                                        <ItemStyle Width="20px"></ItemStyle>
                                    </telerik:GridButtonColumn>
                                    <telerik:GridBoundColumn DataField="StockCategoryId" UniqueName="StockCategoryId" ItemStyle-Width="100px" ReadOnly="true" Display="false" ForceExtractValue="Always">
                                        <ItemStyle Width="100px"></ItemStyle>
                                    </telerik:GridBoundColumn>

                                    <telerik:GridBoundColumn DataField="Name" FilterControlAltText="Filter Name column" HeaderText="Nombre" UniqueName="Name" HeaderStyle-Width="200px" MaxLength="50" FilterControlWidth="180px" CurrentFilterFunction="Contains" ShowFilterIcon="false" AutoPostBackOnFilter="true" Display="true" ForceExtractValue="Always">
                                        <ColumnValidationSettings EnableRequiredFieldValidation="true">
                                            <RequiredFieldValidator ForeColor="Red" ErrorMessage="* Requerido" SetFocusOnError="true"></RequiredFieldValidator>
                                        </ColumnValidationSettings>

                                        <HeaderStyle Width="200px"></HeaderStyle>
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn DataField="ParentStockCategoryId" UniqueName="ParentStockCategoryId" ItemStyle-Width="100px" ReadOnly="true" Display="false" ForceExtractValue="Always">
                                        <ItemStyle Width="100px"></ItemStyle>
                                    </telerik:GridBoundColumn>
                                    <telerik:GridTemplateColumn HeaderText="Imagen" UniqueName="ImageUrl" DataField="ImageUrl" Display="true" HeaderStyle-Width="50px" AllowFiltering="false" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" ForceExtractValue="Always">
                                        <ItemTemplate>
                                            <asp:Image ID="ImageOriginal" ImageUrl='<%# GetPathImage(Eval("ImageUrl").ToString()) %>' runat="server" AlternateText='<%# Eval("ImageUrl") + " 32px, 32px" %>' />
                                        </ItemTemplate>
                                        <EditItemTemplate>
                                            <telerik:RadAsyncUpload ID="RadUpload1" HideFileInput="true" ToolTip='<%# Eval("ImageUrl") %>' InitialFileInputsCount="1" MaxFileInputsCount="1" Localization-Remove="Eliminar" Localization-Select="Buscar" OverwriteExistingFiles="true" ControlObjectsVisibility="None" runat="server"
                                                OnClientFileUploaded="OnClientFileUploaded" AllowedFileExtensions="jpg,png,gif" OnClientValidationFailed="validationFailed">
                                            </telerik:RadAsyncUpload>
                                        </EditItemTemplate>

                                        <HeaderStyle HorizontalAlign="Center" Width="50px"></HeaderStyle>

                                        <ItemStyle HorizontalAlign="Center"></ItemStyle>
                                    </telerik:GridTemplateColumn>
                                </Columns>

                                <EditFormSettings EditFormType="Template">
                                    <EditColumn InsertText="Agregar" UpdateText="Actualizar" CancelText="Cancelar" ButtonType="ImageButton"></EditColumn>
                                    <FormTemplate>
                                         <fieldset>
                                        <legend>Información de Categorías</legend>
                                        <table cellpadding="2" cellspacing="2">
                                            <tr>
                                                <td>Nombre:</td>
                                                <td>
                                                    <telerik:RadTextBox ID="txtName" runat="server" Text='<%# Eval("Name") %>'>
                                                    </telerik:RadTextBox>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td colspan="2" style="vertical-align: top" class="metro">
                                                    <div class="span3 bg-cyan padding5 text-center">
                                                        <h3 class="fg-white">Icono</h3>
                                                    </div>

                                                </td>
                                            </tr>
                                            <tr>
                                                <td colspan="2" style="vertical-align: top" class="metro">
                                                    <div id="DragAndDropImage" class="span3 bg-cyan padding10 text-center buzz-out">
                                                        <h6 class="fg-white">Arrastra el icono que deseas subir</h6>
                                                    </div>
                                                   
                                                </td>
                                                <td>
                                                     Se recomienda usar iconos PNG de tamaño 48px x 48px
                                                </td>
                                            </tr>
                                            <tr>
                                                <td colspan="2" style="vertical-align: top">
                                                    <telerik:RadAsyncUpload ID="RadAsyncUploadImage"
                                                        runat="server"
                                                        AllowedFileExtensions=".jpg,.png"
                                                        ControlObjectsVisibility="None"
                                                        DropZones="#DragAndDropImage"
                                                        HideFileInput="True"
                                                        Localization-Remove="Eliminar"
                                                        Localization-Select="Buscar imagen"
                                                        MaxFileInputsCount="1"
                                                        OverwriteExistingFiles="true"
                                                        Skin="MetroTouch"
                                                        OnClientValidationFailed="validationFailed"
                                                        EnableInlineProgress="False"
                                                        Width="100%"
                                                        ToolTip='<%# Eval("ImageUrl") %>' 
                                                        ChunkSize="0"
                                                        CssClass="buzz-out" />
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <telerik:RadButton ID="RadButton1" runat="server" Text="Salvar" Image-ImageUrl="~/Template/Icons/16px/insert.gif" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>' Height="18px" Width="18px">
                                                    </telerik:RadButton>
                                                    <telerik:RadButton ID="RadButton2" runat="server" Text="Cancelar" Image-ImageUrl="~/Template/Icons/16px/cancel.gif" CommandName="Cancel" Height="18px" Width="18px">
                                                    </telerik:RadButton>
                                                </td>
                                                <td>&nbsp;</td>
                                            </tr>
                                        </table>
                                    </fieldset>
                                         <telerik:RadTextBox ID="txtStockCategoryId" runat="server" Text='<%# Eval("StockCategoryId") %>' Display="false" />                                                    
                                         <telerik:RadTextBox ID="txtParentStockCategoryId" runat="server" Text='<%# Eval("ParentStockCategoryId") %>' Display="false" />                                                    
                                    </FormTemplate>


                                    <PopUpSettings Modal="True"></PopUpSettings>
                                </EditFormSettings>
                            </MasterTableView>
                            <GroupingSettings CaseSensitive="False"></GroupingSettings>

                            <ClientSettings EnableRowHoverStyle="true">
                                <Scrolling AllowScroll="True" UseStaticHeaders="True" SaveScrollPosition="True"></Scrolling>
                                <Selecting AllowRowSelect="True"></Selecting>
                                <ClientEvents OnPopUpShowing="PopUpShowing" />
                            </ClientSettings>
                            <FilterMenu EnableImageSprites="False"></FilterMenu>
                        </telerik:RadGrid>
                    </td>
                </tr>
            </table>
        </div>
    </form>
</body>
</html>
